import { getVerificationCode, getFormSearch, submitSMSAuthentication } from 'services/EnterVerificationCodeService'

export default {
    namespaces: 'enterVerificationCodeModel',
    state: {},
    effects: {
        *sendVCode({ payload, callback }, { call, put }) {
            const res = yield getVerificationCode(payload)
            const { code, message } = res
            if(/0000$/.test(code)) {
                callback('success')
            } else {
                callback('error', message)
            }
        },
        *submit({ payload, callback }, { call, put }) {
            const res = yield submitSMSAuthentication(payload)
            const { code, message } = res
            if(/0000$/.test(code)) {
                return {
                    status: 'success',
                    msg: message
                }
            } else {
                return {
                    status: 'error',
                    msg: message
                }
            }
        },
        *getFormSearch({ payload, callback }, { call, put }) {
            const res = yield getFormSearch(payload)
            const { code, forms, message } = res
            if(/0000$/.test(code) && forms.length !== 0) {
                return {
                    status: 'success',
                    forms,
                    message
                }
            } else {
                return {
                    status: 'error',
                    forms,
                    message
                }
            }
        }
    }
}